//
//  IndexCollectionView.m
//  MyMovie
//
//  Created by Weiwei on 16/3/2.
//  Copyright © 2016年 bever贝沃汇力 weiwei. All rights reserved.
//

#import "IndexCollectionView.h"
#import "HomeModel.h"
@implementation IndexCollectionView
//由于继承了baseCollectionView
//只要重写init（baseCollectionView）方法 itemWidth+注册单元格
//重写单元格的创建



-(id)initWithFrame:(CGRect)frame{
    
    //1.保留父类的方法（baseCollectionView）
    self = [super initWithFrame:frame];
    if(self){
        
        //2.设置单元格宽度
        self.itemWidth = 100;
        //3.注册单元格
        [self registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"index_cell"];
        
    }
    
    return self;
    
}
//重写父类创建cell
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"index_cell" forIndexPath:indexPath];
    
    //考虑复用
    for (UIView* subView in cell.contentView.subviews) {
        [subView removeFromSuperview];
    }
    
    //利用父类提供的dataList属性获得当前Model
    HomeModel* model = self.dataList[indexPath.row];
    
    //创建imageView，并且给数据
    UIImageView* imageView = [[UIImageView alloc]initWithFrame:cell.contentView.bounds];
    [imageView setImageWithURL:[NSURL URLWithString:model.img]];
    
    
    [cell.contentView addSubview:imageView];
    
    
    return cell;
    
    
    
}


@end
